﻿#pragma once

#include "../MonsterObject.h"
#include "../PlayerObject.h"
#include "../../../Shared/Data/ItemData.h"
#include "../../../Shared/Enums.h"
#include "../../MirDatabase/MonsterInfo.h"
#include "../MapObject.h"
#include <string>
#include "exceptionhelper.h"

using namespace Server::MirDatabase;
namespace S = ServerPackets;

namespace Server::MirObjects::Monsters
{
    class Trainer : public MonsterObject
    {
    private:
        PlayerObject *_currentAttacker = nullptr;
        int _hitCount = 0, _totalDamage = 0;
        long long _lastAttackTime = 0, _StartTime = 0;
        bool Poisoned = false;

    public:
        virtual ~Trainer()
        {
            delete _currentAttacker;
        }

    protected:
        bool getCanAttack() const override;
        bool getCanMove() const override;
        //protected override bool CanRegen { get { return false; } }
        bool DropItem(UserItem *item) override;
        bool DropGold(unsigned int gold) override;

        void Attack() override;
        //protected override void ProcessRegen() { }
        void ProcessRoam() override;

    public:
        bool getBlocking() const override;
        bool IsAttackTarget(PlayerObject *attacker) override;
        bool IsAttackTarget(MonsterObject *attacker) override;

        void Die() override;
        void ReceiveChat(const std::string &text, ChatType type) override;

    protected:
        Trainer(MonsterInfo *info);

    public:
        void Spawned() override;

        void Process() override;

        // Player attacking trainer.
        int Attacked(PlayerObject *attacker, int damage, DefenceType type = DefenceType::ACAgility, bool damageWeapon = false) override;

        // Pet attacking trainer.
        int Attacked(MonsterObject *attacker, int damage, DefenceType type = DefenceType::ACAgility) override;

        int Struck(int damage, DefenceType type = DefenceType::ACAgility) override;

        void PoisonDamage(int damage, MapObject *attacker) override;

    protected:
        void ProcessRegen() override;

    public:
        void ChangeHP(int amount) override;


    private:
        void ReportDamage(int damage, DefenceType type, bool Pet);

        void ResetStats();

        void OutputAverage();
    };
}
